package com.pubinfo.passbook.common.enums;

import com.pubinfo.passbook.common.exception.ServiceException;
import com.pubinfo.passbook.common.model.vo.base.BusinessErrorCode;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

/**
 * 合同状态枚举
 */
@Getter
public enum ContractStatusEnum {
  ALL(100, "全部"),
  NO_CLAIM(0, "未认领"),
  CLAIMED(10, "已认领"),
  CLOSE(20, "关闭"),
  ;
  
  private Integer status;
  
  private String desc;
  
  ContractStatusEnum(Integer status, String desc) {
        this.status = status;
        this.desc = desc;
    }
  
  public static ContractStatusEnum getEnum(Integer status) {
    for (ContractStatusEnum e : ContractStatusEnum.values()) {
      if (status.equals(e.getStatus())) {
        return e;
      }
    }
    throw new ServiceException(BusinessErrorCode.STATUS_NOT_EXIST);
  }
  
  public static Integer getStatusCodeByName(String status) {
    for (ContractStatusEnum e : ContractStatusEnum.values()) {
      if (status.equals(e.getDesc())) {
        return e.getStatus();
      }
    }
    throw new ServiceException(BusinessErrorCode.STATUS_NOT_EXIST);
  }
  
  public static List<String> getValues() {
    List<String> descs = new ArrayList<>();
    for (ContractStatusEnum e : values()) {
      if (e.getStatus() != ContractStatusEnum.ALL.getStatus()) {
        
        descs.add(e.getDesc());
      }
    }
    return descs;
  }
}
